package com.china08.yxyapi.api.manage.edu.platform.news;

import java.lang.reflect.InvocationTargetException;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.mg.platform.YxyHomeNews;
import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.mg.YxyHomeNewsRepository;

import io.swagger.annotations.ApiOperation;

/**
 * 教育局平台办公 新闻管理 新增
 * 
 */
@CrossOrigin
@RestController
public class NewsGetController extends YxyApiBaseController {

    @Autowired
    private YxyHomeNewsRepository yhnr;

    @ApiOperation(value = "教育局获得咨询详情")
    @RequestMapping(value = "/api_yw/manage/edu/platform/news/get", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespModel precess(@RequestBody ReqModel reqModel) throws IllegalAccessException, InvocationTargetException {
        RespModel model = new RespModel();
        YxyHomeNews homeNews = yhnr.findById(reqModel.id);
        Assert.notNull(homeNews, "不存在");
        BeanUtils.copyProperties(homeNews, model);
        model.setMessage("成功");
        return model;
    }

    protected static class ReqModel extends YxyApiReqModel {
        public String id;

        @Override
        public void autoCheck() {
            Assert.notNull(StringUtils.defaultIfBlank(id, null), "请指定咨询");
        }

    }

    protected static class RespModel extends YxyApiRespModel {
        public String id;
        public String title;
        public String cover;
        public String content;

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        public String getTitle() {
            return title;
        }

        public void setTitle(String title) {
            this.title = title;
        }

        public String getCover() {
            return cover;
        }

        public void setCover(String cover) {
            this.cover = cover;
        }

        public String getContent() {
            return content;
        }

        public void setContent(String content) {
            this.content = content;
        }

    }
}
